package com.example.sa.myapp.handleDataClient;


import com.example.sa.myapp.sqlModel.*;

import java.util.ArrayList;

public class TestCart {

	public static void main(String[] args) {
		// 购物车放在这个数组
		int uid = 1;

		ArrayList<Cart> cara = new ArrayList<Cart>();

		handleData.getCart(cara, uid);

		for (int i = 0; i < cara.size(); i++) {
			System.out.println(cara.get(i).getProductId() + " " + cara.get(i).getAddNum());
		}
		
		Cart c = new Cart();
		c.setId(1);
		c.setAddNum(10);
		c.setProductId("P004");
		int state = handleData.addCart(c);
		if (state == 2) {
			System.out.println("添加成功");
		}else if (state == 1) {
			System.out.println("添加失败");
		}
		
		c = new Cart();
		c.setId(1);
		c.setAddNum(14);
		c.setProductId("P004");
		state = handleData.alterCart(c);
		if (state == 2) {
			System.out.println("修改成功");
		}else if (state == 1) {
			System.out.println("修改失败");
		}
		
		c = new Cart();
		c.setId(1);
		c.setProductId("P003");
		state = handleData.dropCart(c);
		if (state == 2) {
			System.out.println("删除成功");
		}else if (state == 1) {
			System.out.println("删除失败");
		}
		
		cara.clear();

		handleData.getCart(cara, uid);

		for (int i = 0; i < cara.size(); i++) {
			System.out.println(cara.get(i).getProductId() + " " + cara.get(i).getAddNum());
		}
	}

}
